package org.jasper.impl.compiler.bean;

import org.jasper.api.compiler.bean.BeanCreator;
import org.jasper.api.session.KieSession;
import org.jasper.api.session.KieSessionModel;

/**
 * Created by OP038074 on 2018/8/3.
 */
public class InjectionHelper {
    public static void wireListnersAndWIHs(KieSessionModel model, KieSession kSession) {
        wireListnersAndWIHs(BeanCreatorHolder.beanCreator, model, kSession);
    }

    public static void wireListnersAndWIHs(BeanCreator beanCreator, KieSessionModel model, KieSession kSession) {

    }

    private static class BeanCreatorHolder {
        private static final BeanCreator beanCreator = loadBeanCreator();

        private static BeanCreator loadBeanCreator() {
            BeanCreator beanCreator = lookupCdiBeanCreator();
            return beanCreator != null ? beanCreator : new ReflectionBeanCreator();
        }

        private static BeanCreator lookupCdiBeanCreator() {
            try {
                return (BeanCreator) Class.forName( "org.drools.cdi.CDIHelper" )
                        .getMethod( "getCdiBeanCreator" ).invoke( null );
            } catch (Exception e) {
                return null;
            }
        }
    }
}
